/**
 * 添加指定名称的cookie；addCookie(name,value,expireHours)
 * @param {Object} name 名称
 * @param {Object} value 值
 * @param {Object} expireHours 设置超时时间，小于0则不设置
 */
function addCookie(name, value, expireHours){
    var cookieString = name + "=" + escape(value);
    //判断是否设置过期时间
    if (expireHours > 0) {
        var date = new Date();
        date.setTime(date.getTime + expireHours * 3600 * 1000);
        cookieString = cookieString + "; expire=" + date.toGMTString();
    }
    document.cookie = cookieString;
}

/**
 * 获取指定名称的cookie值：getCookie(name)
 * @param {Object} name 返回名称为name的cookie值，如果不存在则返回空
 */
function getCookie(name){
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (arr[0] == name) 
            return arr[1];
    }
    return "";
}

/**
 * 删除指定名称的cookie：deleteCookie(name)
 * @param {Object} name 删除指定名称的cookie
 */
function deleteCookie(name){
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=v; expire=" + date.toGMTString();
}
